using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using Curriculum.Business.Manejadores;

namespace Curriculum.UI
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtNombre;
		private System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.txtNombre = new System.Windows.Forms.TextBox();
			this.treeView1 = new System.Windows.Forms.TreeView();
			this.button1 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// txtNombre
			// 
			this.txtNombre.Location = new System.Drawing.Point(408, 0);
			this.txtNombre.Name = "txtNombre";
			this.txtNombre.TabIndex = 0;
			this.txtNombre.Text = "";
			// 
			// treeView1
			// 
			this.treeView1.ImageIndex = -1;
			this.treeView1.Location = new System.Drawing.Point(16, 32);
			this.treeView1.Name = "treeView1";
			this.treeView1.SelectedImageIndex = -1;
			this.treeView1.TabIndex = 1;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(40, 304);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 8);
			this.label1.Name = "label1";
			this.label1.TabIndex = 3;
			this.label1.Text = "label1";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(192, 304);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 4;
			this.textBox1.Text = "textBox1";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(528, 357);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.treeView1);
			this.Controls.Add(this.txtNombre);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		/*[STAThread]
		static void Main() 
		{
			//Application.Run(new Form1());
			Application.Run(new frmVersiones());
		}*/

		private void Form1_Load(object sender, System.EventArgs e)
		{
			// Initialize the controls and the form.
			label1.Text = System.Configuration.ConfigurationSettings.AppSettings["pathVersionXML"];
			label1.SetBounds(8, 8, 50, 20);
			textBox1.Text = System.Configuration.ConfigurationSettings.AppSettings["pathVersionXML"];
			textBox1.SetBounds(64, 8, 256, 20);
			button1.Text = "Populate the TreeView with XML";
			button1.SetBounds(8, 40, 200, 20);
			this.Text = "TreeView control from XML";
			this.Width = 336;
			this.Height = 368;
			treeView1.SetBounds(8, 72, 312, 264);
			
			//			
			ManejadorAtributos mAtributos = new ManejadorAtributos();
			txtNombre.Text = mAtributos.GetFirstValue();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			
			/*			try 
			{
				// SECTION 1. Create a DOM Document and load the XML data into it.
				XmlDocument dom = new XmlDocument();
				dom.Load(textBox1.Text);

				// SECTION 2. Initialize the TreeView control.
				treeView1.Nodes.Clear();
				treeView1.Nodes.Add(new TreeNode(dom.DocumentElement.Name));				
				TreeNode tNode = new TreeNode();
				tNode = treeView1.Nodes[0];

				// SECTION 3. Populate the TreeView with the DOM nodes.
				AddNode(dom.DocumentElement, tNode);
				treeView1.ExpandAll();
			}
			catch(XmlException xmlEx)
			{
				MessageBox.Show(xmlEx.Message);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}		
			*/
		}
		private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
		{
/*			XmlNode xNode;
			TreeNode tNode;
			XmlNodeList nodeList;
			int i;

			// Loop through the XML nodes until the leaf is reached.
			// Add the nodes to the TreeView during the looping process.
			if (inXmlNode.HasChildNodes && inXmlNode.LocalName!="atributos")
			{
				nodeList = inXmlNode.ChildNodes;
				for(i = 0; i<=nodeList.Count - 1; i++)
				{
					xNode = inXmlNode.ChildNodes[i];
					inTreeNode.Nodes.Add(new TreeNode(xNode.Name));					
					tNode = inTreeNode.Nodes[i];
					AddNode(xNode, tNode);										
				}
			}
			else
			{
				// Here you need to pull the data from the XmlNode based on the
				// type of node, whether attribute values are required, and so forth.
				if(inXmlNode.LocalName!="atributos")
					inTreeNode.Text = (inXmlNode.OuterXml).Trim() + "aa";
			}
		*/
		}               
	}
}
